﻿
@{
    ViewBag.Title = "添加管理员";
}
@model KTD.Web.Models.VD.MemberCUD

<div class="x-body" id="saveResult" style="width:100%;">
    <div class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>姓名
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(model => model.name, new { @class = "layui-input" })
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>用户名
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(n => n.UserName, new { @class = "layui-input" })
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(model => model.PassWord, new { @class = "layui-input", @type = "password" })
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(model => model.PassWord, new { @class = "layui-input", @type = "password" })
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button id="btnAdd" class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </div>
</div>



@section scripts{
    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

         

            //监听提交
            form.on('submit(add)', function (data) {

                if ($("#name").val() == "") {
                    layer.alert("姓名不能为空", { icon: 5 }, function () {
                        return false;
                    });
                }
                 if ($("#UserName").val() == "") {
                    layer.alert("登录名不能为空", { icon:5 }, function () {
                        return false;
                    });
                }
                 if ($("#PassWord").val() == "") {
                    layer.alert("密码不能为空", { icon:5 }, function () {
                        return false;
                    });
                }
                 if ($("#RePassWord").val() != $("#PassWord").val() ){
                    layer.alert("两次密码不一致", { icon:5 }, function () {
                        return false;
                    });
                }
                var formdata = new FormData();
                formdata.append("UserName", $("#UserName").val());
                formdata.append("name", $("#name").val());
                formdata.append("PassWord", $("#PassWord").val());
                $.ajax({

                    url: "/Member/Create",
                    type: "post",
                    data: formdata,
                    processData: false,    // 不处理数据
                    contentType: false,    // 不设置内容类型

                    success: function (data) {

                        //发异步，把数据提交给php
                        layer.alert("新增成功", { icon: 6 }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.window.location.reload();
                        });
                    }
                })
                return false;
            });


        });

    </script>
}